<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>列表</title>
<link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
<link rel="stylesheet" href="/static/zTree/css/metroStyle/metroStyle.css" type="text/css">
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="/static/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="/static/zTree/js/jquery.ztree.excheck.js"></script>
<script src="/static/layui/layui.all.js"></script>
<script src="/static/js/webutil.js?t=123"></script>
<style type="text/css">
.t_lable{text-align:right;background-color: #F8F8F8}
.t_content{text-align:left}
</style>
</head>
<body>
	<div class="layui-field-box">
		<ul id="menuTree" class="ztree"></ul>
		<form class="layui-form" id="table_form" action="">
		<input type="hidden" value="" id="ids" name="ids">
		<input type="hidden" value="${roleid}" id="roleid" name="roleid">
		
		<button class="layui-btn layui-btn-xs" lay-submit="" lay-filter="*" style="float: right">
			<i class="layui-icon">&#xe618;</i>保存
		</button>
		</form>
	</div>
	<script type="text/javascript">
		var treeObj = null;
		var setting = {
				view: {
					showIcon: true
				},
				check: {
					enable: true
				},
			data: {
				simpleData: {
					enable: true
				}
			},
			 
			callback: {
				onClick:function(event, treeId, treeNode, clickFlag) {
					location.href=location.origin+location.pathname+"?id="+treeNode.id;
				}
			}
		};
	
		var zNodes =[
			<#list list as sysMenu>
			{id:'${sysMenu.id}', pId:'${sysMenu.pid}', name:"${sysMenu.name}", open:true,<#if sysMenu.delflag=='1'>checked:true</#if>},
			</#list>
		];
	
		$(document).ready(function(){
			treeObj = $.fn.zTree.init($("#menuTree"), setting, zNodes);
		});
	</script>
</body>
<script type="text/javascript">
	layui.form.on('submit(*)', function(formData) {
		
		var nodes = treeObj.getCheckedNodes();
		var ids = "";
		for(var i=0;i<nodes.length;i++){
			ids+=nodes[i].id+",";
		}
		$("#ids").val(ids);
		postData('/base/sysrole/savePermission.json');
		return false;
	});
</script>
</html>